package top.heathylife.gateway.common.utils;

import cn.hutool.core.codec.Base64;
import cn.hutool.crypto.asymmetric.KeyType;
import cn.hutool.crypto.asymmetric.RSA;

/**
 * @author maoxiaomeng
 */
public class SecretJsonUtils {

    static final String PR = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAOI9tZ0hiCw9yu+K6cR19bEZja5RWaSk5n5s+2H74dsYD6Vjq9CYKBZPbZbBbQ+OKkoKe2mMCoArz73Z2oMXyqpcaMyU6eX1+z9NqwVhtuZI6UEtKRWjyCmwibLD2yUH5Yfnt1O5RSO09IUt7bloh221nlbLKXW+IBhvDiEnDvprAgMBAAECgYAZPXg3BQgro2MyEUXeQKi97tNjKLk/CJSccy0ic9bxOgB426NN/MOwJYFc6cxwiVRHeV7mWhTL0td030qlCHD4Fdr4DfaruiScLhRaJRBYjmKEl5lOuEdVNYddwY706ySHJsiwskUXJFn29I/Fw4m54GVN6gRBWnGEWvMqw4Zj5QJBAP4hWmbSInXyhewSdvrI4uufyssAO/ayDasrMGWlPCAzfRTu3npi/7VRZHM7Z+0znIa/oDprDwt88hqDqqyGCEUCQQDj59Pnlej4jkDyPCF2BVPsCKLUKp/0IGdf4EI56WyIwjnD7OhV+2xfiPZPSQEZBx+XV+sgbrudnchAJRL/wVrvAkAw0tmabX6/aFPAch+3uMaX/EAq1iWvFLA5lXeb3634hcvfLLFDlCeKf1OsK9qgoMzOupwe/RiL3XpqC6fLs4h9AkEAxGY64b75ZoFIjLeu6kMLIEQM9iPJdhsamq/qwnda9bvTBfm5+qbRrL6d7JNwI75UxhqY4Hksq1aWhFiut8JL9wJALRSdF6fS5H6yDTzO2lgv/Gue/xI7s0IAcUg8hs8LwGtqG7gbfpVtmRuB0dHFp+AaHl2f9d/K+f0+/p6+Wrp35w==";

    static final String PU = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDiPbWdIYgsPcrviunEdfWxGY2uUVmkpOZ+bPth++HbGA+lY6vQmCgWT22WwW0PjipKCntpjAqAK8+92dqDF8qqXGjMlOnl9fs/TasFYbbmSOlBLSkVo8gpsImyw9slB+WH57dTuUUjtPSFLe25aIdttZ5Wyyl1viAYbw4hJw76awIDAQAB";

    /**
     * 加密
     *
     * @param json 字段说明
     */
    public static String encryptBase64(String json) {
        RSA rsa = new RSA(PR, null);
        byte[] bytes = rsa.encrypt(json, KeyType.PrivateKey);
        String encode = Base64.encode(bytes);
        return encode;
    }

    /**
     * 解密
     *
     * @param json 字段说明
     */
    public static String decodeBase64(String json) {
        RSA rsas = new RSA(null, PU);
        byte[] decode = Base64.decode(json);
        byte[] encrypt = rsas.decrypt(decode, KeyType.PublicKey);
        json = new String(encrypt);
        return json;
    }
}
